home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / peer_script.expect < prev    next >
Encoding:
Text File  |  2005-09-29  |  2.8 KB  |  135 lines

  1. #! /usr/local/bin/expect
  2. # TSO login script, which runs as a peer of x3270.
  3. # expect version
  4.  
  5. # Set up login parameters
  6. set tcp_host ibmhost
  7. set dial_user VTAM
  8. set sna_host TSO
  9. set userid USERID
  10. set password PASSWORD
  11.  
  12. # Send x3270 Enter.
  13. proc x3270_enter {} {
  14.     send "Enter()\r"
  15.     expect "*ok\r\n"
  16. }
  17.  
  18. # Fetch text from the screen.
  19. proc x3270_ascii {coords} {
  20.     send "Ascii($coords)\r"
  21.     expect {
  22.     -re "data: (.*)\r\n.*\r\nok\r\n$" {
  23.         return $expect_out(1,string)
  24.     }
  25.     }
  26.     send_user "Ascii failed.\n"
  27. }
  28.  
  29. # Display an error message and exit.
  30. proc x3270_error {text} {
  31.     global spid
  32.     send "Info(\042$text\042)\r"
  33.     expect "*ok\r\n"
  34.     send "CloseScript\r"
  35.     expect "*ok\r\n"
  36.     close -i $spid
  37.     exit
  38. }
  39.  
  40. #############################################################################
  41. # Start of main procedure.
  42.  
  43. # Start x3270
  44. set stty_init -echo
  45. spawn -noecho -ignore SIGHUP x3270 -script -model 2 -color
  46. set spid $spawn_id
  47.  
  48. # Connect to host
  49. set connected 0
  50. while {$connected == 0} {
  51.     send "Connect($tcp_host)\r" ; send "Wait()\r"
  52.     expect {
  53.       "U F U C($tcp_host)*" {
  54.     set connected 1
  55.       }
  56.       default {
  57.     send "Disconnect()\r"
  58.     expect "*ok\r\n"
  59.     exec sleep 3
  60.       }
  61.     }
  62. }
  63.  
  64. # Get to a VM command screen
  65. x3270_enter
  66.  
  67. # Wait for VM's prompt
  68. set enter 0
  69. while {$enter==0} {
  70.     if {"[x3270_ascii 1,0,5]" == "Enter"} {set enter 1} {sleep 2}
  71. }
  72.  
  73. # Dial out to VTAM
  74. send "String(\042DIAL $dial_user\042)\r"
  75. expect "*ok\r\n"
  76. x3270_enter
  77.  
  78. # No proper way I can think of to do this: let the DIAL command digest
  79. exec sleep 2
  80.  
  81. # "DIALED TO xxx" may momentarily flash
  82. set dialed 0
  83. while {$dialed==0} {
  84.     if {"[x3270_ascii 8,0,80]" == "DIALED TO $dial_user"} {exec sleep 2} {set dialed 1}
  85. }
  86.  
  87. # Make sure we are dialed to VTAM
  88. if {"[x3270_ascii 0,64,4]" != "VTAM"} { x3270_error "Couldn't get to VTAM" }
  89.  
  90. # Get to the SNA host
  91. send "String(\042$sna_host $userid\042)\r"
  92. x3270_enter
  93.  
  94. # Pass VTAM digestion message
  95. set digested 0
  96. while {$digested==0} {
  97.     if {"[x3270_ascii 0,21,20]" == "USS COMMAND HAS BEEN"} {exec sleep 2} {set digested 1}
  98. }
  99.  
  100. # Now verify the "TSO/E LOGON" screen
  101. if {"[x3270_ascii 0,33,11]" != "TSO/E LOGON"} {
  102.     x3270_error "Couldn't get to TSO logon screen"
  103. }
  104.  
  105. # Pump in the password
  106. send "String($password)\r"
  107. x3270_enter
  108.  
  109. # Now look for "LOGON IN PROGRESS"
  110. set timeout 600
  111. set sl [expr "18 + [string length $userid]"]
  112. if {"[x3270_ascii 0,11,$sl]" != "$userid LOGON IN PROGRESS"} {
  113.     x3270_error "Couldn't log on"
  114. }
  115.  
  116. # Make sure TSO is waiting for a '***' enter
  117. set timeout 10
  118. send "\r"
  119. expect {
  120.     -re ".* (.*) 0x.*\r\nok\r\n" {
  121.     if {$expect_out(1,string) != "5" } {
  122.         x3270_error "Don't understand logon screen"
  123.     }
  124.     }
  125. }
  126.  
  127. # Off to ISPF
  128. x3270_enter
  129.  
  130. # We're in; exit the script and let the user interact.
  131. send "CloseScript\r"
  132. expect "*ok\r\n"
  133. close -i $spid
  134. exit
  135.